<template>
     <el-dialog  :modelValue="props.visible" title="编辑用户" :before-close="close">
    <el-form :model="formdata">
      <el-form-item label="账号">
        <el-input v-model="formdata.nickName" autocomplete="off" />
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="formdata.username" autocomplete="off" />
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="formdata.email" autocomplete="off" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="formdata.password" type="password" autocomplete="off" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="formdata.note" autocomplete="off" />
      </el-form-item>
      <el-form-item label="是否启用：">
        <el-radio v-model="formdata.status" :label="1">是</el-radio>
        <el-radio v-model="formdata.status" :label="0">否</el-radio>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="submit">
          确定
        </el-button>
      </span>
    </template> 
  </el-dialog>
</template>
<script setup>
import { reactive, toRefs,watch ,getCurrentInstance} from 'vue';
import {USERADMINE_EDIT_POST} from '../../../api/index'
const {proxy}=getCurrentInstance()
const props=defineProps({
    visible:Boolean,
    form:{}
})
const emit = defineEmits(['close','refresh'])
const state=reactive({
    formdata:{}
})
const{formdata}=toRefs(state)
watch(()=>props.form,()=>{
    formdata.value={...props.form}
})
//点击确定提交
const submit=()=>{
  proxy.$request({
    url:USERADMINE_EDIT_POST+`/${formdata.value.id}`,
    method:'post',
    data:{
      ...formdata.value
    }
  }).then((res)=>{
   if (res.code==200) {
      close()
   }
  })
}
// 点击关闭
const close = () => {
  emit('close','editadmin')
  emit('refresh')
}
</script>
<style scoped lang="scss">
</style>